package com.hhit.collaborative_learning.learning;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql;
import com.hhit.collaborative_learning.utils.Utils;
import com.mysql.jdbc.StringUtils;

@MultipartConfig
public class ApplyExpertServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String realName=request.getParameter("RealName");
		String mobile=request.getParameter("Mobile");
		Part file=request.getPart("file1");
		String tag=request.getParameter("tag");
		String category=request.getParameter("Channe");
		String qq=request.getParameter("QQ");
		qq=StringUtils.isNullOrEmpty(qq)?"":qq;
		String address=request.getParameter("Address");
		String description=request.getParameter("Description");
		String userId=request.getParameter("userId");
		String path = getServletContext().getRealPath("/userIcons");
		String realicon=Utils.saveImage(path, file);
		PublicDaoImplMySql dao=new PublicDaoImplMySql();
		if(dao.applyExpert(Integer.parseInt(userId), realName, realicon, mobile, category,tag, qq, address, description)){
			request.getRequestDispatcher("learning/apply_expert_result.jsp").forward(request, response);
		}
	}

}
